home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 February / enter-2006-02.iso / files / Illustrator_CS2_ue_TryOut.exe / bridge / Adobe Bridge 1.0.msi / Data1.cab / _0prefsDialog.jsx < prev    next >
Encoding:
Text File  |  2005-03-24  |  24.4 KB  |  634 lines

  1. /**************************************************************************
  2. *
  3. *  @@@BUILDINFO@@@ 60prefsDialog.jsx 1.0.0.47 07-Feb-2005
  4. *  Copyright 2005 Adobe Systems Incorporated
  5. *  All Rights Reserved.
  6. *
  7. * NOTICE:  All information contained herein is, and remains the property of
  8. * Adobe Systems Incorporated  and its suppliers,  if any.  The intellectual 
  9. * and technical concepts contained herein are proprietary to  Adobe Systems 
  10. * Incorporated  and its suppliers  and may be  covered by U.S.  and Foreign 
  11. * Patents,patents in process,and are protected by trade secret or copyright 
  12. * law.  Dissemination of this  information or reproduction of this material
  13. * is strictly  forbidden  unless prior written permission is  obtained from 
  14. * Adobe Systems Incorporated.
  15. **************************************************************************/
  16.  
  17. // Code to create the Preferences dialog
  18.  
  19. //    TODO
  20. /*
  21. ? how to handle font names not in the 'prefsFontNames' list?
  22.   Should 'other' bring up a separate font selection dialog?
  23. */
  24.  
  25. /////////////////////////////////////////////////////////////////////////
  26. // Define an 'onSelect' method for the Preferences menu item that will
  27. // open the Preferences dialog and update the preferences when dismissed.
  28.  
  29. if (editMenu.preferences)
  30. editMenu.preferences.onSelect = function()
  31. {
  32.     /////////////////////////////////////////////////////////////////////////
  33.     // Local variables
  34.  
  35.     var kFontStyleBold = 1;
  36.     var kFontStyleItalic = 2;
  37.     var kFontStyleUnderlined = 4;
  38.  
  39.  
  40.     /////////////////////////////////////////////////////////////////////////
  41.     // The preferences dialog resource
  42.  
  43.     var prefsDlgResSpec =
  44.     "dialog {                                                                    \
  45.         text:'$$$/ESToolkit/PreferencesDlg/title=Preferences',                    \
  46.         orientation:'column',                                                    \
  47.         selector: DropDownList {                                                \
  48.             alignment:'left',                                                    \
  49.             helpTip:'$$$/ESToolkit/PreferencesDlg/htSelector=Select the preference options to change'    \
  50.         },                                                                        \
  51.         panes:    Panel {                                                            \
  52.             text:'temp', orientation:'stack', margins:[15,20,15,15]                \
  53.         }                                                                        \
  54.     }";
  55.  
  56.     /////////////////////////////////////////////////////////////////////////
  57.     // The text formatting options pane resource
  58.  
  59.     var textFormattingOptsResSpec = 
  60.     "group {                                                                    \
  61.         orientation:'column', alignChildren:'left', visible:false,                \
  62.         autoIndent:    Checkbox {                                                    \
  63.             text:'$$$/ESToolkit/PreferencesDlg/autoindent=I&ndent new lines',    \
  64.             helpTip:'$$$/ESToolkit/PreferencesDlg/htAutoindent=Indent new lines to same level as previous line'    \
  65.         },                                                                        \
  66.         lineNums:    Checkbox {                                                    \
  67.             text:'$$$/ESToolkit/PreferencesDlg/linenumbers=&Display line numbers',    \
  68.             helpTip:'$$$/ESToolkit/PreferencesDlg/htLinenumbers=Show line numbers to the left of text in an edit pane' \
  69.         },                                                                        \
  70.         hilite:        Checkbox {                                                    \
  71.             text:'$$$/ESToolkit/PreferencesDlg/hilite=&Enable syntax highlighting',    \
  72.             helpTip:'$$$/ESToolkit/PreferencesDlg/htHilite=Highlight JavaScript reserved words, comments, etc, with different colors',    \
  73.         },                                                                        \
  74.         tabStops:    Group {                                                        \
  75.             lbl:    StaticText {                                                \
  76.                 text:'$$$/ESToolkit/PreferencesDlg/tabstops=Tab stops:' },        \
  77.             list:    DropDownList {                                                \
  78.                 helpTip:'$$$/ESToolkit/PreferencesDlg/htTabstops=Choose the number of spaces between tab stops'    \
  79.             }                                                                    \
  80.         }                                                                        \
  81.     }";
  82.  
  83.  
  84.     /////////////////////////////////////////////////////////////////////////
  85.     // The Font options pane resource
  86.  
  87.     var fontOptionsResSpec = 
  88.     "group {                                                                    \
  89.         orientation:'column', alignChildren:'left', visible:false,                \
  90.         txtName:    Group {                                                        \
  91.             lbl:    StaticText {                                                \
  92.                 text:'$$$/ESToolkit/PreferencesDlg/textFont=Text font:' },        \
  93.             list:    DropDownList {                                                \
  94.                 helpTip:'$$$/ESToolkit/PreferencesDlg/htTextFont=Choose the font to display text'    \
  95.             }                                                                    \
  96.         },                                                                        \
  97.         txtSize:    Group {                                                        \
  98.             lbl:    StaticText {                                                \
  99.                 text:'$$$/ESToolkit/PreferencesDlg/textSize=Text size:' },        \
  100.             list:    DropDownList {                                                \
  101.                 helpTip:'$$$/ESToolkit/PreferencesDlg/htTextSize=Choose the font size to display text'    \
  102.             }                                                                    \
  103.         },                                                                        \
  104.         txtStyle:    Panel {                                                        \
  105.             text:'$$$/ESToolkit/PreferencesDlg/textStyle=Text style',            \
  106.             orientation:'row', alignment:'center',                                \
  107.             bold:    Checkbox {                                                    \
  108.                 text:'$$$/ESToolkit/PreferencesDlg/bold=&Bold',                    \
  109.                 helpTip:'$$$/ESToolkit/PreferencesDlg/htBold=Use a bold typeface to display text'    \
  110.             },                                                                    \
  111.             italic:    Checkbox {                                                    \
  112.                 text:'$$$/ESToolkit/PreferencesDlg/italic=&Italic',                \
  113.                 helpTip:'$$$/ESToolkit/PreferencesDlg/htItalic=Use an italic typeface to display text'    \
  114.             }                                                                    \
  115.         }                                                                        \
  116.     }";
  117.  
  118.  
  119.     /////////////////////////////////////////////////////////////////////////
  120.     // The "help" options pane resource
  121.  
  122.     var helpOptionsResSpec = 
  123.     "group {                                                                    \
  124.         orientation:'column', alignChildren:'left', visible:false,                \
  125.         dynamicHelp:    Checkbox {                                                \
  126.             text:'$$$/ESToolkit/PreferencesDlg/dynamichelp=Display JavaScript &variables',\
  127.             helpTip:'$$$/ESToolkit/PreferencesDlg/hiDynamichelp=Show types and values of variables when you rest the mouse cursor over them' }, \
  128.         helpTips:        Checkbox {                                                \
  129.             text:'$$$/ESToolkit/PreferencesDlg/helptips=Enable UI &help tips',    \
  130.             helpTip:'$$$/ESToolkit/PreferencesDlg/htHelptips=Display a help message when you rest the mouse cursor over a control in the user interface' }    \
  131.     }";
  132.  
  133.  
  134.     /////////////////////////////////////////////////////////////////////////
  135.     // The general options pane resource
  136.  
  137.     var generalOptionsResSpec = 
  138.     "group {                                                                    \
  139.         orientation:'column', alignChildren:'left', visible:false,                \
  140.         language:    Group {                                                        \
  141.             orientation:'row',                                                    \
  142.             lbl:    StaticText {                                                \
  143.                 text:'$$$/ESToolkit/PreferencesDlg/language=Language:' },        \
  144.             list: DropDownList {                                                \
  145.                 helpTip:'$$$/ESToolkit/PreferencesDlg/htLanguage=Select the language to present in the user interface'    \
  146.             }                                                                    \
  147.         },                                                                        \
  148.         scripts:    Group {                                                        \
  149.             orientation:'column', alignChildren:'left',                            \
  150.             lbl:    StaticText {                                                \
  151.                 text:'$$$/ESToolkit/PreferencesDlg/scriptsfolder=Scripts folder:' },    \
  152.             folder: Group {                                                        \
  153.                 path:    EditText {                                                \
  154.                     preferredSize:[220,20],                                        \
  155.                     helpTip:'$$$/ESToolkit/PreferencesDlg/htFolder=Pathname of the folder that contains scripts' \
  156.                 },                                                                \
  157.                 browse:    Button {                                                \
  158.                     text:'$$$/ESToolkit/PreferencesDlg/browse=&Browse...',            \
  159.                     helpTip:'$$$/ESToolkit/PreferencesDlg/htFolderBrowse=Use a folder selection dialog to choose the folder that contains scripts' \
  160.                 }                                                                \
  161.             }                                                                    \
  162.         },                                                                        \
  163.         cleanWorkspace: Checkbox {                                                \
  164.             text:'$$$/ESToolkit/PreferencesDlg/cleanWorkspace=&Start with a clean workspace',    \
  165.             helpTip:'$$$/ESToolkit/PreferencesDlg/htCleanWorkspace=On startup, do not open any files from the previous session' \
  166.         }                                                                        \
  167.     }";    
  168.  
  169.  
  170.     /////////////////////////////////////////////////////////////////////////
  171.     // The buttons group resource
  172.  
  173.     var btnsResSpec = 
  174.     "group {                                                                    \
  175.         alignment:'right',                                                        \
  176.         okBtn:        Button { text:'$$$/CT/ExtendScript/UI/OK=OK',                \
  177.                             properties:{ name:'ok' } },                            \
  178.         cancelBtn:    Button { text:'$$$/CT/ExtendScript/UI/Cancel=Cancel',        \
  179.                             properties:{ name:'cancel' } }                        \
  180.     }"
  181.  
  182.     
  183.     /////////////////////////////////////////////////////////////////////////
  184.     // Create the dialog
  185.  
  186.     initDialogPrefs();
  187.  
  188.     var prefsDlg = new Window (prefsDlgResSpec);
  189.  
  190.     //    Create the text formatting options pane
  191.     prefsDlg.panes.textFormattingOptionsPane = prefsDlg.panes.add (textFormattingOptsResSpec);
  192.     initTextFormattingOptions (prefsDlg.panes.textFormattingOptionsPane);
  193.  
  194.     //    Create the font options pane
  195.     prefsDlg.panes.fontOptionsPane = prefsDlg.panes.add (fontOptionsResSpec);
  196.     initFontOptions (prefsDlg.panes.fontOptionsPane);
  197.  
  198.     //    Create the help options pane
  199.     prefsDlg.panes.helpOptionsPane = prefsDlg.panes.add (helpOptionsResSpec);
  200.     initHelpOptions (prefsDlg.panes.helpOptionsPane);
  201.  
  202.     //    Create the general options pane
  203.     prefsDlg.panes.generalOptionsPane = prefsDlg.panes.add (generalOptionsResSpec);
  204.     initGeneralOptions (prefsDlg.panes.generalOptionsPane);
  205.     
  206.     //    Initialize the 'selector' list that chooses which preference pane to show
  207.     var prefsPanes = prefsDlg.panes;
  208.     initSelectorList (
  209.         prefsDlg.selector, prefsPanes,
  210.         [
  211.         "$$$/ESToolkit/PreferencesDlg/textTitle=Text formatting options", prefsPanes.textFormattingOptionsPane,
  212.         "$$$/ESToolkit/PreferencesDlg/fontTitle=Font options", prefsPanes.fontOptionsPane,
  213.         "$$$/ESToolkit/PreferencesDlg/helpTitle=Help options", prefsPanes.helpOptionsPane,
  214.         "$$$/ESToolkit/PreferencesDlg/generalTitle=General options", prefsPanes.generalOptionsPane
  215.         ]);
  216.  
  217.     //    Finally, create the OK and Cancel buttons
  218.     prefsDlg.btns = prefsDlg.add (btnsResSpec);
  219.     with (prefsDlg.btns) {
  220.         //    Dialog window is 2 levels in hierarchy up from the buttons
  221.         okBtn.onClick = function () { this.parent.parent.close(1); }
  222.         cancelBtn.onClick = function () { this.parent.parent.close(2); }
  223.     }
  224.  
  225.     //    When the dialog is shown, re-locate 'pane selector' list to the top of the panes panel
  226.     prefsDlg.onShow = positionSelectorList;
  227.     
  228.     /////////////////////////////////////////////////////////////////////////
  229.     // Configure the dialog, show it, and set any changed preferences
  230.  
  231.     configureDialogFromPrefs (prefsDlg, prefs.preferencesDialogPrefs);
  232.     var ok = prefsDlg.show() == 1;
  233.     updateDialogPrefs (prefsDlg, prefs.preferencesDialogPrefs);
  234.  
  235.     if (ok) {
  236.         setFontOptionPreferences (prefsDlg.panes.fontOptionsPane);
  237.         setTextFormattingPreferences (prefsDlg.panes.textFormattingOptionsPane);
  238.         setHelpPreferences (prefsDlg.panes.helpOptionsPane);
  239.         setGeneralPreferences (prefsDlg.panes.generalOptionsPane);
  240.     }
  241.  
  242.  
  243.     /////////////////////////////////////////////////////////////////////////
  244.     // initFontOptions: initialize the font options pane
  245.  
  246.     function initFontOptions (pane)
  247.     {
  248.         var item, i;
  249.         var fontNames = ["Application", "System", "Monospace", "Serif", "SansSerif"];
  250.         var prefsFontNames = ["*application", "*system", "*monospace", "*serif", "*sansserif"];
  251.         var textSizes = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72];
  252.         with (pane) {
  253.             //    Create a list of text font names and select the preferred one
  254.             for (i = 0; i < fontNames.length; i++) {
  255.                 item = txtName.list.add ( "item", fontNames[i]);
  256.                 item.prefsName = prefsFontNames[i];
  257.                 if (item.prefsName == prefs.fontName)
  258.                     txtName.list.selection = item;
  259.             }
  260.  
  261.             //    Create a list of text font sizes and select the preferred one
  262.             for (i = 0; i < textSizes.length; i++) {
  263.                 item = txtSize.list.add ( "item", textSizes[i]);
  264.                 if (item.text == prefs.fontSize)
  265.                     txtSize.list.selection = item;
  266.             }
  267.  
  268.             //    Show the preferred text style
  269.             txtStyle.bold.value = prefs.fontFace & kFontStyleBold;
  270.             txtStyle.italic.value = prefs.fontFace & kFontStyleItalic;
  271.         }
  272.     } // initFontOptions
  273.  
  274.  
  275.     /////////////////////////////////////////////////////////////////////////
  276.     // setFontOptionPreferences: set preferences from the selected font options
  277.     function setFontOptionPreferences (pane)
  278.     {
  279.         with (pane) {
  280.             if (txtName.list.selection != null)
  281.                 prefs.fontName = txtName.list.selection.prefsName;
  282.             if (txtSize.list.selection != null)
  283.                 prefs.fontSize = txtSize.list.selection.text;
  284.             var newFontFace = 0;
  285.             if (txtStyle.bold.value)
  286.                 newFontFace += kFontStyleBold;
  287.             if (txtStyle.italic.value)
  288.                 newFontFace += kFontStyleItalic;
  289.             prefs.fontFace = newFontFace;
  290.         }
  291.     } // setFontOptionPreferences
  292.  
  293.  
  294.     /////////////////////////////////////////////////////////////////////////
  295.     // initTextFormattingOptions: initialize the text formatting options pane
  296.  
  297.     function initTextFormattingOptions (pane)
  298.     {
  299.         var i;
  300.         var tabStopSettings = [2, 4, 6, 8, 12, 16];
  301.         with (pane) {
  302.             //    Load the current text formatting preferences
  303.             autoIndent.value = prefs.autoIndent;
  304. //            wrap.value = prefs.wrap;
  305.             lineNums.value = prefs.lineNumbers;
  306.             hilite.value = prefs.hilite;
  307.             
  308.             //    Load the possible tab stops and select the preferred one
  309.             for (i = 0; i < tabStopSettings.length; i++) {
  310.                 item = tabStops.list.add ( "item", tabStopSettings[i]);
  311.                 if (item.text == prefs.tabs)
  312.                     tabStops.list.selection = item;
  313.             }
  314.         }
  315.     } // initTextFormattingOptions
  316.  
  317.  
  318.     /////////////////////////////////////////////////////////////////////////
  319.     // setTextFormattingPreferences: set preferences from the selected font options
  320.     function setTextFormattingPreferences (pane)
  321.     {
  322.         with (pane) {
  323.             prefs.autoIndent = autoIndent.value == 1;
  324.             
  325. //            prefs.wrap = wrap.value == 1;
  326.             
  327.             prefs.lineNumbers = lineNums.value == 1;
  328.             MenuElement.find('edit/lines').checked = prefs.lineNumbers;
  329.             
  330.             prefs.hilite = hilite.value == 1;
  331.             MenuElement.find('edit/hilite').checked = prefs.hilite;
  332.             
  333.             if (tabStops.list.selection != null)
  334.                 prefs.tabs = tabStops.list.selection.text;
  335.         }
  336.     } // setTextFormattingPreferences
  337.  
  338.  
  339.     /////////////////////////////////////////////////////////////////////////
  340.     // initHelpOptions: initialize the help options pane
  341.  
  342.     function initHelpOptions (pane)
  343.     {
  344.         with (pane) {
  345.             //    Load the current help preferences
  346.             dynamicHelp.value = prefs.dynamicHelp;
  347.             helpTips.value = prefs.helpTips;
  348.         }
  349.     } // initHelpOptions
  350.  
  351.  
  352.     /////////////////////////////////////////////////////////////////////////
  353.     // setHelpPreferences: set preferences from the selected help options
  354.     function setHelpPreferences (pane)
  355.     {
  356.         with (pane) {
  357.             prefs.dynamicHelp = dynamicHelp.value == 1;
  358.             
  359.             prefs.helpTips = helpTips.value == 1;
  360.         }
  361.     } // setHelpPreferences
  362.  
  363.  
  364.     /////////////////////////////////////////////////////////////////////////
  365.     // initGeneralOptions: initialize the general options pane
  366.  
  367.     function initGeneralOptions (pane)
  368.     {
  369.         /*    We determine the list of supported languages by searching the 'required'
  370.             folder for all the .dat files: each one has the translations of all
  371.             strings shown in our UI, and each file begins with an identifying string
  372.             of the form "$$$/ESToolkit/A/Language=English" that tells us what language
  373.             it is for. The name of a .dat file is the locale for the language translations
  374.             it contains. */
  375.         var i, item;
  376.         var languageFiles = app.requiredFolder.getFiles ('*.dat');
  377.         var languages = new Array();
  378.         var key = "$$$/ESToolkit/A/Language=";
  379.         for (i = 0; i < languageFiles.length; i++) {
  380.             if (languageFiles[i].open("r")) {
  381.                 var data = languageFiles[i].read();
  382.                 var loc = data.indexOf (key);
  383.                 if (loc >= 0) {
  384.                     loc += key.length;
  385.                     var s = data.substring (loc, data.indexOf ('"', loc));
  386.                     //    Get locale name from the file name
  387.                     var locale = ":" + languageFiles[i].name;
  388.                     //    Strip off the .dat extension and append to language name
  389.                     languages.push (s + locale.substring (0, locale.length - 4));
  390.                 }
  391.             }
  392.         }
  393.         languages.sort();
  394.  
  395.         with (pane) {
  396.             //    Create list of languages, headed by a 'Default' item
  397.             item = language.list.add ("item", "$$$/ESToolkit/PreferencesDlg/defaultLang=Default");
  398.             item.locale = $.locale;
  399.             language.list.add ("separator");
  400.         
  401.             //    If there's no prefs file for locale, the 'Default' item is selected
  402.             var localePrefsFile = new File (prefs.createFolder() + "/locale.txt");
  403.             if (localePrefsFile.open ("r"))
  404.                 localePrefsFile.close();
  405.             else
  406.                 language.list.selection = item;
  407.  
  408.             //    Load the language items, noting the 'selected' one if not using the Default (above)
  409.             for (i = 0; i < languages.length; i++) {
  410.                 var languageLocale = languages[i].split(":");
  411.                 item = language.list.add ("item", languageLocale[0]);
  412.                 item.locale = languageLocale[1];
  413.                 if (language.list.selection == null && item.locale == prefs.locale)
  414.                     language.list.selection = item;
  415.             }
  416.             //    Remember which item we marked as the selection, to tell if it changed later
  417.             language.list.initialSelection = language.list.selection.index;
  418.  
  419.             //    If only 1 (or no) language choices, disable the language selector
  420.             if (languages.length <= 1)
  421.                 language.list.enabled = false;
  422.  
  423.             //    Load the current scripts pathname
  424.             var scriptsFolder = Folder (prefs.scripts);
  425.             scripts.folder.path.text = scriptsFolder.fsName;
  426.  
  427.             //    Create a "select folder" dialog for the Browse button
  428.             scripts.folder.browse.onClick = function ()
  429.                 {
  430.                     //    Let user select a new scripts folder: show the current one
  431.                     var folderEditText = this.parent.path;
  432.                     var currentScriptsFolder = Folder(folderEditText.text);
  433.                     var selectTitle = localize ("$$$/ESToolkit/PreferencesDlg/selectScripts=Select the scripts folder");
  434.                     var newFolder = Folder.selectDialog (selectTitle, currentScriptsFolder);
  435.                     if (newFolder != null)
  436.                         folderEditText.text = newFolder.fsName;
  437.                 }
  438.  
  439.             //    Load the current 'start with clean workspace' setting
  440.             cleanWorkspace.value = prefs.cleanWorkspace;
  441.         }
  442.     } // initGeneralOptions
  443.  
  444.  
  445.     /////////////////////////////////////////////////////////////////////////
  446.     // setGeneralPreferences: set preferences from the selected general options
  447.     function setGeneralPreferences (pane)
  448.     {
  449.         with (pane) {
  450.             //    Use the specified language if it has changed
  451.             var selectedLanguage = language.list.selection;
  452.             if ((selectedLanguage != null) &&
  453.                 (language.list.initialSelection != selectedLanguage.index))
  454.             {
  455.                 var updatedOK = false;
  456.                 prefs.locale = selectedLanguage.locale;
  457.  
  458.                 //    Create a path to the 'locale pref' file
  459.                 var fld = prefs.createFolder();
  460.                 var localePrefFile = new File (fld + "/locale.txt");
  461.  
  462.                 //    The 'Default' language item is always at list index 0.
  463.                 var isDefault = selectedLanguage.index == 0;
  464.                 if (isDefault) {
  465.                     //    If 'Default' was selected, delete the obsolete 'locale pref' file
  466.                     updatedOK = localePrefFile.remove();
  467.                 }
  468.                 else {
  469.                     // create or update the locale pref file
  470.                     updatedOK = localePrefFile.open ("w");
  471.                     if (updatedOK) {
  472.                         localePrefFile.writeln (prefs.locale);
  473.                         localePrefFile.close();
  474.                     }
  475.                 }
  476.             
  477.                 if (updatedOK)
  478.                     messageBox ("$$$/ESToolkit/Language/OK=The new language setting will take effect the next time the program starts.");
  479.                 else
  480.                     errorBox ("$$$/ESToolkit/Language/Error=Cannot switch to the new language!");
  481.             }
  482.  
  483.             //    Use the specified scripts path if it has changed
  484.             var currScriptsFolder = Folder (prefs.scripts);
  485.             if (currScriptsFolder.fsName != scripts.folder.path.text) {
  486.                 var newScriptsFolder = Folder (scripts.folder.path.text);
  487.                 prefs.scripts = newScriptsFolder.absoluteURI;
  488.             }
  489.  
  490.             //    Set the 'start with clean workspace' option
  491.             prefs.cleanWorkspace = cleanWorkspace.value != 0;
  492.         }
  493.     } // setGeneralPreferences
  494.  
  495.  
  496.     /////////////////////////////////////////////////////////////////////////
  497.     /*    initSelectorList
  498.         Setup the list to show 1 pane for each list item.
  499.         'selector' is the DropDownList that will contain names of preference panes.
  500.         'panes' is the panel that the selector list should be positioned over
  501.         'selections' is an array of "title, pane" pairs, where 'pane' is the
  502.         pane to make visible when the given 'title' is selected in the list.
  503.     */
  504.     function initSelectorList (selector, panes, selections)
  505.     {
  506.         //    Load the list with preference pane titles
  507.         var pair;
  508.         for (pair = 0; pair < selections.length; pair += 2) {
  509.             item = selector.add ("item", localize(selections[pair]));
  510.             item.pane = selections[pair+1];
  511.         }
  512.         
  513.         /*    When a list item is selected, hide the currently visible preference pane
  514.             and show the one corresponding to the selected item. */
  515.         selector.onChange = function ()
  516.             {
  517.                 var paneToShow = this.selection.pane;
  518.                 this.currPane.hide();
  519.                 paneToShow.show();
  520.                 this.currPane = paneToShow;
  521.             }
  522.     } // initSelectorList
  523.  
  524.  
  525.     /////////////////////////////////////////////////////////////////////////
  526.     //    positionSelectorList: an onShow() callback for the prefsDlg window
  527.     function positionSelectorList ()
  528.     {
  529.         //    Move the 'selector' list from just above the panes Panel to the top of
  530.         //    the panes Panel, indented 15 pixels from the left and straddling the border
  531.         this.selector.location.x = this.panes.location.x + 15;
  532.         
  533.         /*    Move the 'panes' and 'btns' panels up to center the 'panes' border under
  534.             the selector list. The calculation first determines how far to move
  535.             to get the panes top at the top of the selector list (which is too far),
  536.             then it backs off by adjusting for the height of the title area in the
  537.             panes panel. We use the height of any StaticText element to get the
  538.             height of the panel title. */
  539.         var crunchSpace = this.spacing + this.selector.size.height;
  540.         crunchSpace -= ((this.selector.size.height - this.panes.generalOptionsPane.language.lbl.size.height) / 2);
  541.         this.panes.location.y -= crunchSpace;
  542.         this.btns.location.y -= crunchSpace;
  543.         
  544.         //    Make the dialog correspondingly shorter
  545.         this.size.height -= crunchSpace;
  546.     } // positionSelectorList
  547.  
  548.  
  549.     /////////////////////////////////////////////////////////////////////////
  550.     //    initDialogPrefs()
  551.     //    Initialize the 'preferenceDialogPrefs' object, creating it if necessary.
  552.     function initDialogPrefs()
  553.     {
  554.         // If necessary, create an initial 'preferencesDialogPrefs' property on the
  555.         // global 'prefs' object, to hold the user preferences for the Preferences dialog
  556.  
  557.         var prefsObj = { allProperties:[ ["dialogLocation", null], ["selectedPane", 0] ] };
  558.         if (typeof prefs.preferencesDialogPrefs == "undefined") {
  559.             //    Create initial prefs object and define default property values
  560.             for (var i = 0; i < prefsObj.allProperties.length; i++)
  561.                 prefsObj[prefsObj.allProperties[i][0]] = prefsObj.allProperties[i][1];
  562.             prefs.preferencesDialogPrefs = prefsObj;
  563.         }
  564.  
  565.         if (typeof prefs.preferencesDialogPrefs.initDone == "undefined") {
  566.             // Finish 'first-time thru' setup of preferencesDialogPrefs object
  567.             prefs.preferencesDialogPrefs.initDone = true;
  568.             prefs.preferencesDialogPrefs.allProperties = prefsObj.allProperties;
  569.             
  570.             /* Define the toSource() method of the preferencesDialogPrefs object
  571.                to return a string that is executable code which creates the
  572.                preferencesDialogPrefs object at initialization time. */
  573.             prefs.preferencesDialogPrefs.toSource = function()
  574.             {
  575.                 /*    Iterate thru the preferencesDialog preference properties, appending each
  576.                     property name / value pair to the source string we are building */
  577.                 var src = "{ ";
  578.                 for (var i = 0; i < this.allProperties.length; i++) {
  579.                     if (i > 0)
  580.                         src += ", ";
  581.                     src += strVal (this, this.allProperties[i][0]);
  582.                 }
  583.                 src += " }";
  584.                 return src;
  585.                 
  586.                 //    Utility that returns a string for the named 'prop' / value pair
  587.                 function strVal (prefs, prop)
  588.                 {
  589.                     var str = prop + ": ";
  590.                     var value = prefs[prop];
  591.                     if (typeof value == 'object')
  592.                         str += value.toSource();
  593.                     else if (typeof value == "string")
  594.                         str += "'" + value.toString() + "'";
  595.                     else
  596.                         str += value.toString();
  597.                     return str;
  598.                 }
  599.             }
  600.         }
  601.     } // initDialogPrefs
  602.  
  603.  
  604.     /////////////////////////////////////////////////////////////////////////
  605.     //    configureDialogFromPrefs()
  606.     //    Initialize dialog settings from the saved 'preferenceDialogPrefs' values.
  607.     //    Called on each 'show' of the preferences dialog.
  608.     function configureDialogFromPrefs (dlg, dlgPrefs)
  609.     {
  610.         if (dlgPrefs.dialogLocation != null)
  611.             dlg.location = dlgPrefs.dialogLocation;
  612.         else
  613.             //    Location unknown: center over the main window
  614.             dlg.center(window);
  615.         
  616.         //    Show the last known preferences pane
  617.         dlg.selector.selection = dlgPrefs.selectedPane;
  618.         dlg.selector.currPane = dlg.selector.selection.pane;
  619.     } // configureDialogFromPrefs
  620.  
  621.  
  622.     /////////////////////////////////////////////////////////////////////////
  623.     //    updateDialogPrefs()
  624.     //    Update the 'preferenceDialogPrefs' object with current dialog settings.
  625.     function updateDialogPrefs (dlg, dlgPrefs)
  626.     {
  627.         //    Remember dialog screen location
  628.         dlgPrefs.dialogLocation = dlg.location;
  629.         //    Remember what prefences pane was selected
  630.         dlgPrefs.selectedPane = dlg.selector.selection.index;
  631.     } // updateDialogPrefs
  632.  
  633. } // end of onSelect function
  634.